package cn.itsource.basic.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AjaxResult {

    private String code = PetHomeConstant.SYSTEM_SUCCESS;
    private String message = "操作成功!";
    private boolean success = true;
    private Object data = null;

    public static AjaxResult ok() {
        return new AjaxResult();
    }

    public static AjaxResult ok(Object obj) {
        return new AjaxResult(PetHomeConstant.SYSTEM_SUCCESS, "操作成功！", true, obj);
    }

    public static AjaxResult error(String message) {
        return error(PetHomeConstant.SYSTEM_ERROR, message);
    }

    public static AjaxResult error(String code, String message) {
        return new AjaxResult(code, message, false, null);
    }

    public static AjaxResult toAjax(boolean result) {
        return result ? ok() : error("操作失败!");
    }

    public static AjaxResult toAjax(boolean result, String message) {
        return result ? ok(message) : error(message);
    }
}
